/*
* @Author: JINPENG
* @Date:   2018-05-28 21:39:10
* @Last Modified by:   JINPENG
* @Last Modified time: 2018-11-07 19:52:52
*/
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin')

// 环境变量配置，dev / online
var WEBPACK_ENV         = process.env.WEBPACK_ENV || 'dev';
//获取html-webpack-plugin 参数的名字
var getHtmlConfig = function(name,title){
    return {
            template  : './src/view/'+name+'.html',
            filename  : 'view/'+name+'.html',
            inject    : true,
            favicon   :'./favicon.ico',
            title     : title,
            hash      :true,
            chunks    :['common',name]
    }
}
var config= {
    entry: {
    	'common'                : ['./src/page/common/index.js'],
        'index'                 : ['./src/page/index/index.js'],
        'list'                  : ['./src/page/list/index.js'],
        'detail'                : ['./src/page/detail/index.js'],
        'cart'                  : ['./src/page/cart/index.js'],
        'order-confirm'         : ['./src/page/order-confirm/index.js'],
        'order-list'            : ['./src/page/order-list/index.js'],
        'order-detail'          : ['./src/page/order-detail/index.js'],
        'order-payment'         : ['./src/page/order-payment/index.js'],
        'user-login'            : ['./src/page/user-login/index.js'],
        'user-register'         : ['./src/page/user-register/index.js'],
        'user-pass-reset'       : ['./src/page/user-pass-reset/index.js'],
        'user-center'           : ['./src/page/user-center/index.js'],
        'user-center-update'    : ['./src/page/user-center-update/index.js'],
        'user-pass-update'      : ['./src/page/user-pass-update/index.js'],
        'result'                : ['./src/page/result/index.js'],
        'about'                 : ['./src/page/about/index.js'],
    },
    output: {
        path        : './dist/',
        publicPath  : 'dev' === WEBPACK_ENV ? '/dist/' : '//s.jpstudy.top/mmall-fe/dist/',
        filename    : 'js/[name].js'
    },
     externals : {
    	'jquery' :'window.jQuery'

    },
    module: {
	  	loaders: [
	  		{ test: /\.(gif|png|jpg|woff|svg|eot|ttf)\??.*$/, loader:'url-loader?limit=100&name=resource/[name].[ext]' },  // 
            { test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader","css-loader")}, // 单独打包出CSS，这里配置注意下
	        { 
                test        : /\.string$/,
                loader      :'html-loader',
                query       : 
                 {
                    minimize : true,
                    removeAttributeQuotes : false 
                 }

             }
      ]
},
     resolve : {
        alias : {
            node_modules    : __dirname + '/node_modules',
            util            : __dirname + '/src/util',
            page            : __dirname + '/src/page',
            service         : __dirname + '/src/service',
            image           : __dirname + '/src/image'
        }
    },
    plugins:[
         //独立通用模块js/base.js
    	new webpack.optimize.CommonsChunkPlugin({
    		name : 'common',
    		filename : 'js/base.js'
    	}),
        //css独立打包
        new ExtractTextPlugin("css/[name].css"),
        //HTML模板
        new HtmlWebpackPlugin(getHtmlConfig('index','首页')),
        new HtmlWebpackPlugin(getHtmlConfig('user-login','登录')),
        new HtmlWebpackPlugin(getHtmlConfig('list','商品列表')),
        new HtmlWebpackPlugin(getHtmlConfig('detail','商品详情页')),
        new HtmlWebpackPlugin(getHtmlConfig('cart','购物车')),
        new HtmlWebpackPlugin(getHtmlConfig('order-confirm','订单确认页')),
        new HtmlWebpackPlugin(getHtmlConfig('order-list','订单列表页')),
        new HtmlWebpackPlugin(getHtmlConfig('order-detail','订单详情页')),
        new HtmlWebpackPlugin(getHtmlConfig('order-payment','订单支付页')),
        new HtmlWebpackPlugin(getHtmlConfig('user-register','注册')),
        new HtmlWebpackPlugin(getHtmlConfig('user-pass-reset','密码重置')),
        new HtmlWebpackPlugin(getHtmlConfig('user-center','个人中心')),
        new HtmlWebpackPlugin(getHtmlConfig('user-center-update','修改个人中心')),
        new HtmlWebpackPlugin(getHtmlConfig('user-pass-update','修改密码')),
        new HtmlWebpackPlugin(getHtmlConfig('result','结果')),
        new HtmlWebpackPlugin(getHtmlConfig('about','结果')),
    ]
};
if ('dev' === WEBPACK_ENV) {
    config.entry.common.push('webpack-dev-server/client?http://localhost:8088');
}
module.exports = config;